import { SEntityInfo } from "../../../../../Message/BroadCast/SEntityInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { Global } from "../../../../../com/gengine/global/Global";
import { LayerManager } from "../../../manager/LayerManager";
import { ListMenu } from "./ListMenu";
import { PlayerMenuCellRenderer } from "./PlayerMenuCellRenderer";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { PetOpMenuConst } from "./PetOpMenuConst";
//class PetOpRegister
    
    export  class PetOpRegister
    {
        

        public static Register(arg1: Object /* flash.display.InteractiveObject */, arg2: SEntityInfo, arg3: DataProvider, arg4: SPetInfo=null): void
        {
            if (!PetOpRegister.HasRegister(arg1)) 
            {
                PetOpRegister._opDataProvider = arg3;
                PetOpRegister._entityInfo = arg2;
                PetOpRegister._petInfo = arg4;
                PetOpRegister._dicObjInfo[arg1] = arg2;
                PetOpRegister._dicObjdata[arg1] = PetOpRegister._opDataProvider;
                arg1.addEventListener(flash.events.MouseEvent.CLICK, PetOpRegister.showInfo);
                Global.stage.addEventListener(flash.events.MouseEvent.CLICK, PetOpRegister.HideHandler);
            }
            return;
        }

        public static UnRegister(arg1: Object /* flash.display.InteractiveObject */): void
        {
            arg1.removeEventListener(flash.events.MouseEvent.CLICK, PetOpRegister.showInfo);
            delete PetOpRegister._dicObjInfo[arg1];
            delete PetOpRegister._dicObjdata[arg1];
            return;
        }

        public static ShowOpList(arg1: SEntityInfo, arg2: number, arg3: number, arg4: DataProvider=null): void
        {
            if (!arg4) 
            {
                arg4 = PetOpRegister._opDataProvider;
            }
            if (!PetOpRegister._layer) 
            {
                PetOpRegister._layer = LayerManager.topLayer;
            }
            PetOpRegister.createPlayerOpList();
            PetOpRegister._entityInfo = arg1;
            PetOpRegister._layer.addChild(PetOpRegister._petOpList);
            PetOpRegister._petOpList.dataProvider = PetOpRegister._opDataProvider;
            arg2 = arg2 < PetOpRegister._layer.stage.stageWidth - PetOpRegister._petOpList.width ? arg2 : arg2 - PetOpRegister._petOpList.width;
            arg3 = arg3 < PetOpRegister._layer.stage.stageHeight - PetOpRegister._petOpList.height ? arg3 : arg3 - PetOpRegister._petOpList.height;
            PetOpRegister._petOpList.show(arg2, arg3, PetOpRegister._layer);
            return;
        }

        public static HasRegister(arg1: Object /* flash.display.InteractiveObject */): Boolean
        {
            return PetOpRegister._dicObjInfo.hasOwnProperty(arg1) ? true : false;
        }

        public static HideOpList(): void
        {
            if (PetOpRegister._petOpList) 
            {
                PetOpRegister._petOpList.hide();
            }
            return;
        }

        /* internal  */static createPlayerOpList(): void
        {
            if (!PetOpRegister._petOpList) 
            {
                PetOpRegister._petOpList = new ListMenu();
                PetOpRegister._petOpList.width = 86;
                PetOpRegister._petOpList.visible = false;
                PetOpRegister._petOpList.list.setStyle("cellRenderer", PlayerMenuCellRenderer);
                PetOpRegister._petOpList.list.drawNow();
                PetOpRegister._petOpList.list.addEventListener(ListEvent.ITEM_CLICK, PetOpRegister.petOpItemSelect);
            }
            return;
        }

        /* internal  */static showInfo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=NaN;
            var loc2=NaN;
            if (!PetOpRegister._layer) 
            {
                PetOpRegister._layer = LayerManager.topLayer;
            }
            PetOpRegister.createPlayerOpList();
            PetOpRegister._currnetActiveObject = arg1.target as Object /* flash.display.InteractiveObject */;
            PetOpRegister._entityInfo = PetOpRegister._dicObjInfo[PetOpRegister._currnetActiveObject];
            if (PetOpRegister._currnetActiveObject.parent) 
            {
                PetOpRegister._layer.addChild(PetOpRegister._petOpList);
                PetOpRegister._petOpList.dataProvider = PetOpRegister._opDataProvider;
                loc1 = arg1.stageX;
                loc2 = arg1.stageY;
                loc1 = loc1 < PetOpRegister._layer.stage.stageWidth - PetOpRegister._petOpList.width ? loc1 : loc1 - PetOpRegister._petOpList.width;
                loc2 = loc2 < PetOpRegister._layer.stage.stageHeight - PetOpRegister._petOpList.height ? loc2 : loc2 - PetOpRegister._petOpList.height;
                PetOpRegister._petOpList.show(loc1, loc2, PetOpRegister._layer);
            }
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */static HideHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            PetOpRegister.HideOpList();
            return;
        }

        /* internal  */static petOpItemSelect(arg1: ListEvent): void
        {
            PetOpMenuConst.Opearte(PetOpRegister._petOpList.list.dataProvider.getItemAt(arg1.index)["label"], PetOpRegister._entityInfo, PetOpRegister._petInfo);
            return;
        }

        /* internal */ static /* var */_petOpList: ListMenu;

        /* internal */ static /* var */_layer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_currnetActiveObject: Object /* flash.display.InteractiveObject */;

        /* internal */ static /* var */_entityInfo: SEntityInfo=null;

        /* internal */ static /* var */_dicObjInfo: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_dicObjdata: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_opDataProvider: DataProvider;

        /* internal */ static /* var */_petInfo: SPetInfo;
    }

            PetOpRegister._entityInfo = null;
            PetOpRegister._dicObjInfo = new Map<any, any> /* flash.utils.Dictionary */(true);
            PetOpRegister._dicObjdata = new Map<any, any> /* flash.utils.Dictionary */(true);
        